﻿// CHisChromViewDlg.cpp: 实现文件
//

#include "stdafx.h"
#include "DC-QC.h"
#include "CHisChromViewDlg.h"
#include "afxdialogex.h"


// CHisChromViewDlg 对话框

IMPLEMENT_DYNAMIC(CHisChromViewDlg, CDialogEx)

CHisChromViewDlg::CHisChromViewDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_HISCHROMVIEWDLG, pParent)
{
	m_nIndex = 0;
}

CHisChromViewDlg::~CHisChromViewDlg()
{
}

void CHisChromViewDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CHisChromViewDlg, CDialogEx)
	ON_WM_SIZE()
	ON_WM_CREATE()
	ON_BN_CLICKED(IDC_BUTTON1, &CHisChromViewDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BTPRE, &CHisChromViewDlg::OnBnClickedBtpre)
	ON_BN_CLICKED(IDC_BTNEXT, &CHisChromViewDlg::OnBnClickedBtnext)
END_MESSAGE_MAP()


// CHisChromViewDlg 消息处理程序

void CHisChromViewDlg::OnSize(UINT nType, int cx, int cy)
{
	CDialogEx::OnSize(nType, cx, cy);

	// TODO: 在此处添加消息处理程序代码
	CRect rect;
	GetClientRect(rect);
	if (m_wndLastCurveA.m_hWnd)
	{
		rect.top = 60;
		rect.DeflateRect(2, 2, 2, 2);
		CRect rt = rect;
		//rt.bottom = rect.top + rect.Height() / 2;
		rt.bottom = rect.top + rect.Height();
		m_wndLastCurveA.MoveWindow(rt);
		rt.top = rt.bottom + 10;
		rt.bottom = rect.bottom;
		//m_wndLastCurveB.MoveWindow(rt);
	}
}

int CHisChromViewDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialogEx::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码
	CRect rect(0, 0, 10, 10);
	m_wndLastCurveA.Create(NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, HCV_CUVE1_ID, NULL);
	//m_wndLastCurveB.Create(NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, HCV_CUVE2_ID, NULL);

	m_wndLastCurveA.SetLineWidth(2);
	//m_wndLastCurveB.SetLineWidth(2);
	return 0;
}

void CHisChromViewDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	CString strFile;
	CFileDialog dlg(true, TEXT("bcf"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT| OFN_ALLOWMULTISELECT, _T("色谱数据文件(*.bcf)|*.bcf||"));
	//要加上如下的代码，要不然有选择的文件个数限制，2021-12-22 zpj
	DWORD MAXFILE = 2562; //2562 is the max
	TCHAR* pc = new TCHAR[MAXFILE * (MAX_PATH + 1) + 1];
	pc[0] = pc[1] = 0;
	dlg.m_ofn.nMaxFile = MAXFILE;
	dlg.m_ofn.lpstrFile = pc;
	if (dlg.DoModal() != IDOK) return;
	else
	{
		m_arrFiles.RemoveAll();
		POSITION pos = dlg.GetStartPosition();
		while (pos != NULL)
		{
			strFile = dlg.GetNextPathName(pos);
			m_arrFiles.Add(strFile);
		}
	}
	m_nIndex = m_arrFiles.GetCount() - 1;
	GetDlgItem(IDC_EDIT1)->SetWindowTextW(strFile);

	cfTest = gl.ReadChmDate(strFile);
	int nType = GetChTypeFromFileName(strFile);
	m_wndLastCurveA.UpdateGraph(cfTest, nType);
}

void CHisChromViewDlg::OnBnClickedBtpre()
{
	// TODO: 在此添加控件通知处理程序代码
	if (m_arrFiles.GetCount() == 0) return;
	CString strFile;
	m_nIndex--;
	if (m_nIndex >= m_arrFiles.GetCount()) m_nIndex = m_arrFiles.GetCount() - 1;
	if (m_nIndex < 0) m_nIndex = 0;
	strFile = m_arrFiles.GetAt(m_nIndex);
	GetDlgItem(IDC_EDIT1)->SetWindowTextW(strFile);

	cfTest = gl.ReadChmDate(strFile);
	int nType = GetChTypeFromFileName(strFile);
	m_wndLastCurveA.UpdateGraph(cfTest, nType);
}


void CHisChromViewDlg::OnBnClickedBtnext()
{
	// TODO: 在此添加控件通知处理程序代码
	CString strFile;
	m_nIndex++;
	if (m_nIndex >= m_arrFiles.GetCount()) m_nIndex = m_arrFiles.GetCount() - 1;
	strFile = m_arrFiles.GetAt(m_nIndex);
	GetDlgItem(IDC_EDIT1)->SetWindowTextW(strFile);

	cfTest = gl.ReadChmDate(strFile);
	int nType = GetChTypeFromFileName(strFile);
	m_wndLastCurveA.UpdateGraph(cfTest, nType);
}
